/*
 * test.c
 *
 * Created: 7/11/2013 12:10:36 PM
 *  Author: Tim
 */ 

#include "test.h"

#include "../packets//CRC.h"

#include "../communication/comPort.h"

#include "../packets/structs/msgHeaderDefs.h"
#include "../packets/structs/adcPacketStructs.h"
#include "../packets/structs/dacPacketStructs.h"
#include "../packets/structs/dioPacketStructs.h"
#include "../packets/structs/encPacketStructs.h"
#include "../packets/structs/flashPacketStructs.h"
#include "../packets/structs/genPacketStructs.h"



void seedStandAloneEnable()
{
	uint8_t i = 0;
	daqStandAloneEn_t packet;

	uint8_t *msg;
	
	msg = &packet;

	packet.Header		= packetHeader;
	packet.msgHeader	= daqStandAloneEn_mh;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);;
	}	
}

void seedStart()
{
	uint8_t i = 0;
	programStart_t packet;

	uint8_t *msg;
	
	msg = &packet;

	packet.Header		= packetHeader;
	packet.msgHeader	= programStart_mh;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);;
	}
}

void seedStop()
{
	uint8_t i = 0;
	programStop_t packet;

	uint8_t *msg;
	
	msg = &packet;

	packet.Header		= packetHeader;
	packet.msgHeader	= programStop_mh;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);;
	}
}

void seedAdcInitAsync()
{
	uint8_t i = 0;
	adcInitAsync_t packet;	
	
	uint8_t *msg;
	
	msg = &packet;
	
	
	packet.Header		= packetHeader;
	packet.msgHeader	= adcInitAsync_mh; 
	
	packet.PARAM1.ACHM	= ADC_CH0_bp | ADC_CH1_bp | ADC_CH2_bp | ADC_CH3_bp ;
	packet.PARAM1.GAIN	= ADC_CH_GAIN_2X_gc>>ADC_CH_GAIN_gp;
	packet.PARAM2.FREQH	= 0;
	packet.PARAM3.FREQL	= 40;
	
	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedAdcFlashInit(uint8_t channelMSK, uint16_t freq, uint16_t samples)
{
	uint8_t i = 0;
	adcFlashInit_t packet;
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= adcFlashInit_mh;
	
	
	packet.PARAM1.ACHM = channelMSK;
	packet.PARAM1.GAIN= ADC_CH_GAIN_2X_gc>>ADC_CH_GAIN_gp;
	
	packet.PARAM2.FREQH = freq>>8;
	
	packet.PARAM3.FREQL = 0x00FF & freq;
	
	packet.PARAM4.SMPSH = samples>>8;
	packet.PARAM5.SMPSL = 0x00FF & samples;
	
	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedDacUpdate()
{
	uint8_t i = 0;
	dacUpdate_t packet;
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= dacUpdate_mh;
	
	packet.PARAM1.DCHM	= 1;

	packet.PARAM1.DVALH = 0x01;
	
	packet.PARAM2.DVALL = 0xFF;
	
	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedDioInitPolling()
{
	uint8_t i = 0;
	dioInitPolling_t packet;
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= dioInitPolling_mh;

	packet.PARAM1.DPFRQH = 0;
	packet.PARAM2.DPFRQL = 64;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedDioOutSet()
{
	uint8_t i = 0;
	dioPins_t packet;
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= dioOutSet_mh;
	
	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedDioOutClr()
{
	uint8_t i = 0;
	dioPins_t packet;	

	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= dioOutClr_mh;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedDioDirSet()
{
	uint8_t i = 0;
	dioPins_t packet;	
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= dioDirSet_mh;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedDioDirClr()
{
	uint8_t i = 0;
	dioPins_t packet;	
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= dioDirClr_mh;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedEncInitAsync()
{
	uint8_t i = 0;
	encInitAsync_t packet;
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= encInitAsync_mh;
	
	packet.PARAM1.ENCN = 0;
	packet.PARAM1.INDX = 1;
	packet.PARAM1.PLOC = 0x29;
	packet.PARAM2.ABS = 0;
	packet.PARAM2.EDFL = 7;
	packet.PARAM2.ERESH = 0;
	packet.PARAM3.ERESL = 0xFF;
	packet.PARAM4.EFRQ = 0;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedGenAck()
{
	uint8_t i = 0;
	xtrg_t packet;
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= xtrg_mh;

	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}

void seedReset()
{
	uint8_t i = 0;
	resetDaq_t packet;
	
	uint8_t *msg;
	
	msg = &packet;
	
	packet.Header		= packetHeader;
	packet.msgHeader	= resetDaq_mh;
	
	crcAppend(&packet,packetSizeLookup(packet.msgHeader));
	for(i=0;i<packetSizeLookup(packet.msgHeader);i++)
	{
		bufferWrite(&bufRxD1,msg[i]);
	}
}
